<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php

include('functions.php');

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  
    $name = trim($_POST['name_FR']);
  
  $errors = array();
  
   if (strlen($name) == 0) {
  	array_push($errors, "Nom ne peut pas être vide");
   } else if (strlen($name) > 40) {
  	array_push($errors, "Nom ne peut pas etre plus long que 40 caracteres");
   }

  if (sizeof($errors) == 0) {
  
	  $updateSQL = sprintf("UPDATE csre_category SET name_FR=%s, name_US=%s WHERE category_id=%s",
						   GetSQLValueString($name, "text"),
						   GetSQLValueString($_POST['name_FR'], "text"),
						   GetSQLValueString($_POST['category_id'], "int"));
	
	  mysql_select_db($database_locamedicadmin, $locamedicadmin);
	  $Result1 = mysql_query($updateSQL, $locamedicadmin) or die(mysql_error());
	
	  $updateGoTo = "category_list.php";
	  if (isset($_SERVER['QUERY_STRING'])) {
		$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
		$updateGoTo .= $_SERVER['QUERY_STRING'];
	  }
	  header(sprintf("Location: %s", $updateGoTo));
  }
}

$colname_category = "-1";
if (isset($_GET['categoryid'])) {
  $colname_category = (get_magic_quotes_gpc()) ? $_GET['categoryid'] : addslashes($_GET['categoryid']);
}
mysql_select_db($database_locamedicadmin, $locamedicadmin);
$query_category = sprintf("SELECT * FROM csre_category WHERE category_id = %s", $colname_category);
$category = mysql_query($query_category, $locamedicadmin) or die(mysql_error());
$row_category = mysql_fetch_assoc($category);
$totalRows_category = mysql_num_rows($category);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
			<h1 class="title2">Modifier une cat&eacute;gorie </h1>
		
			<?php include('errors.php'); ?>	
	  
            <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
              <table>
                <tr valign="baseline">
                  <td nowrap >Name:</td>
                  <td><input type="text" name="name_FR" value="<?php echo getValorReg('name_FR', $row_category); ?>" size="50" maxlength="40"></td>
                </tr>
              </table>
              
			  <div class="botonera">
			  	<input type="submit" value="Save">
				<input type="button" onclick="window.location='category_list.php'" value="Cancel" />
			  </div>
			  
			  <input type="hidden" name="MM_update" value="form1">
              <input type="hidden" name="category_id" value="<?php echo $row_category['category_id']; ?>">
			  
            </form>
            <p>&nbsp;</p>
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($category);
?>
